<template>
	<view>
		<view class="u-rela">
			<view class="u-p-10">
				<u-swiper :list="imgList" @click="swiperUrl" height="300" mode="round" indicator-pos="topRight" img-mode="aspectFill">
				</u-swiper>
			</view>
		</view>
		<view class="bg_FFFFFF">
			<!-- 最新订单 -->
			<view class="neworder  u-p-20 u-flex">
				<u-image src="https://www.sqkjkj.vip/wxImg/common/shop/img.png" mode="aspectFill" width="40rpx" height='40rpx'></u-image>
				<view class="u-flex u-w-700 u-row-between" >
					<view class="cl_676767FF u-m-l-20 u-font-22 cl_FB473CFF">可用积分
						<text class='u_inline-block u-m-l-20 cl_FB473CFF'>{{userinfo.score}}</text>
					</view>
					<view class="u-flex" style="margin-top: -20rpx;" @click="$u.route('/subcontract/myscore/myscore')">
						<view class="u-font-24" style="color:#FB5022FF; margin-top: 20rpx;">查看</view>
						
						<u-image src="https://www.sqkjkj.vip/wxImg/common/shop/img3.png" mode="aspectFill" width="20rpx" height='20rpx'></u-image>
					</view>
				</view>
			</view>
			<!-- 分类商品 -->
			<view class="u-p-20">
				<u-tabs name="title" :list="tabList" :is-scroll="true" active-color="#FB473CFF" :current="tabCurrent" @change="tabChange">
				</u-tabs>
			</view>
		</view>


		<!-- 商品信息-->
		<view class=" u-p-20 ">
			<view class="u-p-30 u-m-t-20 u-flex bg_FFFFFF u-b-r-12" v-for="(item,index) in list" :key="index" style="border-bottom: 1rpx solid #F1F1F1FF;" @click="$u.route('/pages/home/shopmassage?num='+item.spu)">
				<view class=" u-p-20" style="background-color:#EFEFEFFF ;">
					<u-image :src="item.imgs[0]" mode="aspectFill" width="212rpx"height='212rpx'></u-image>
				</view>
				
				<view class=" u-h-212 u-w-600 u-p-20  ">
					<view class=" u-weight">{{item.name}}</view>
					<view class=" u-flex u-p-t-20">
						<view class="u-font-46" style="color: #FF5502FF;">{{item.to_pay_price}}+</view>
						<u-image src="https://www.sqkjkj.vip/wxImg/common/shop/money.png" mode="aspectFill" width="32rpx"height='32rpx'></u-image>
						<view class="u-font-46" style="color: #FF5502FF;">{{item.to_pay_score}}</view>
					</view>
					<view class="u-flex u-row-between u-p-t-10">
						<view class=" u-font-20" >
							已兑换<text style="color:#FC3533FF ;">{{item.sales}}</text>件
						</view>
						<view class="u-w-154 u-h-62 u-l-h-62 u-text-center u-font-20 u-b-r-16" style="background-color:#FF5502FF;color: #FFFFFF">立即兑换</view>
					</view>
				</view>
			</view>
		</view>

		<view class="u-p-20">
			<!-- 加载更多 -->
			<u-loadmore :status="status" icon-type="circle" margin-top="20" margin-bottom="20" />
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				show1:false,
				// 轮播图
				imgList:[],
				// 商品数据
				params: {
					type:2,
					page: 1,
					page_size: 20,
					category_id:''
				},
				// tab切换
				tabCurrent: 0,
				tabList: [],
				status: 'loadmore',
				list: [],
				userinfo:'',
			}
		},
		onLoad() {
			this.userinfo=uni.getStorageSync("userinfo")
			this.get_banner()
			this.get_one_category()
		},
		onShow() {			
		},
		// 下拉到底事件
		onReachBottom() {
			//避免多次触发
			if (this.status == 'loading' || this.status == 'nomore') {
				return;
			}
			this.shop_list();
		},
		methods: {
			// banner
			async get_banner() {
				await this.$api.get_banner({pos:'score_shop'}, res => {
					if (res.data.code == 1) {
						res.data.data.forEach(img => {
							img.image = img.pic
						})
						this.imgList = res.data.data
					}
				})
			},
			// banner
			async get_one_category() {
				await this.$api.get_one_category({pos:'score_shop'}, res => {
					if (res.data.code == 1) {
						res.data.data.unshift({
							id:0,
							level:0,
							pic:'',
							title:'全部商品'
						})
						this.tabList=res.data.data
						if (this.tabList.length >= 0) {
							this.params.category_id = this.tabList[0].id
						}
						this.clear()
						this.shop_list()
					}
				})
			},
			swiperUrl(index){
				this.customUrl(this.imgList[index])
			},
			customUrl(c) {
				if (c.url_type == 'goods_detail') {
					this.$u.route(`/pages/home/paymassage?num=${c.params.spu}`)
				} else if (c.url_type == 'goods_list') {
					this.tabCurrent = this.tabList.findIndex((t, ti) => {
						if (t.id == c.params.category_id) {
							return ti
						}
					})
					this.params.category_id = this.tabList[this.tabCurrent].id
					uni.pageScrollTo({
						selector: '#classId',
						duration: 500
					})
					this.clear()
					this.shop_list()
				} else if (c.url_type == 'shop_detail') {
					this.$u.route(`/pages/shopmassage/shopmassage?num=${c.params.shop_id}`)
				}else if (c.url_type == 'announce_detail') {
					this.$u.route(`/subcontract/mymassage/systemMessages/detail?announce_id=${c.params.announce_id}`)
				}
			},
			// tab切换
			tabChange(index) {
				this.tabCurrent = index
				this.params.category_id = this.tabList[this.tabCurrent].id
				this.clear()
				this.shop_list()
			},
			clear() {
				this.list = [];
				this.params.page = 1;
			},
			// 获取商品列表
			async shop_list() {
				await this.$api.shop_list(this.params, res => {
					if (res.data.code == 1) {
						if (res.data.data.data.length < 20) {
							this.status = 'nomore';
						} else {
							this.params.page = this.params.page + 1;
							this.status = 'loadmore';
						}
						this.list = this.list.concat(res.data.data.data);
						uni.stopPullDownRefresh();
					}
				})
			},
			
		}
	}
</script>

<style scoped>
	page {
		background: #F5F5F5FF !important;
		padding-bottom: 50rpx;
	}

	/* .views1 {
		background: url("https://www.sqkjkj.vip/wxImg/common/img/banner.png") no-repeat;
		background-size: 100% 100%;
	} */

	.neworder {
		background: url("https://www.sqkjkj.vip/wxImg/common/shop/img2.png") no-repeat;
		background-size: 100% 100%;
	}

	.all {
		background: url("https://www.sqkjkj.vip/wxImg/common/home/img9.png") no-repeat;
		background-size: 100% 100%;
	}

	.bas {
		background: url("https://www.sqkjkj.vip/wxImg/common/home/img14.png") no-repeat;
		background-size: 100% 100%;
	}
</style>
